import Canvas from '../../lib/canvas.js'
Page({
  ...Canvas.options,

  /**
   * 页面的初始数据
   */
  data: {
    isHide: false,
    ismulti: false,
    selcetAll: false,
    ifCleanCache: false,
    selectCounts: [],
    canCleanCacheSize: '675M',
    canCleanFile: [{
      title: "视频文件1",
      content: "视频文件的内容演示1",
      fileSize: "3.78M",
      fileTime: "2015-07-14 10:31"
    },
    {
      title: "音频文件1",
      content: "音频文件的内容展示1",
      fileSize: "3.78M",
      fileTime: "2015-08-24 11:31"
    },
    {
      title: "文档文件1",
      content: "文档文件的内容介绍1",
      fileSize: "1.68M",
      fileTime: "2015-05-04 00:31"
    },
    {
      title: "应用文件1",
      content: "应用文件的内容介绍1",
      fileSize: "3.78M",
      fileTime: "2015-07-14 10:31"
    }
    ]
  },

  multichose: function () {
    this.setData({
      ismulti: !this.data.ismulti,
      ifCleanCache: false
    })
    var n = this.data.ismulti

    if (n) {
      this.setData({
        selectCounts: []
      })
    }
  },

  /*打开清除缓存窗口*/
  cacheClean: function () {
    this.setData({
      ifCleanCache: !this.data.ifCleanCache,
      ismulti: false,
      selectCounts: [],
    })
  },


  /*清除缓存*/
  cacheDel: function () {

  },

  checkboxChange: function (e) {
    this.setData({
      selectCounts: this.data.canCleanFile
    })
    console.log(this.data.selectCounts)
  },

  /*全选*/
  allPick: function (e) {
    var that = this
    // let checkedCount = 0;
    // for (let i = 0; i < that.data.canCleanFile.length; i++) {
    //   if (that.data.canCleanFile[i].checked) {
    //     checkedCount++;
    //   }
    // }
    // if (that.data.selectCounts.length < that.data.canCleanFile.length) {
    for (let j = 0; j < that.data.canCleanFile.length; j++) {
      that.data.canCleanFile[j].checked = true
    }
    that.setData({
      canCleanFile: that.data.canCleanFile,
      selcetAll: true,
      selectCounts: that.data.canCleanFile
    })
    // }
    console.log(this.data.selectCounts)
  },

  /*取消全选*/
  cancelAllpick: function () {
    var that = this
    for (let i = 0; i < that.data.canCleanFile.length; i++) {
      that.data.canCleanFile[i].checked = false
    }
    that.setData({
      canCleanFile: that.data.canCleanFile,
      selectCounts: [],
      selcetAll: (!that.data.selcetAll)
    })
  },

  /*删除选定项目*/
  fileDel: function (e) {

  },

  /*取消多选模式*/
  cancelSelect: function () {
    this.setData({
      selectCounts: [],
      ismulti: !this.data.ismulti,
      selcetAll: false
    })
  },

  backToMain: function () {
    wx.redirectTo({
      url: '../main/main',
    })
  },

  changeHideMode: function () {
    this.setData({
      isHide: !this.data.isHide
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // wx.hideTabBar({
    //   animation: true
    // })
    // this表示的对象是Canvas.options
    this.draw('runCanvas', 87, 1000)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})